{% extends "PlatBundle::layout.html.twig" %}

{% block title %}企业列表{% endblock %}

{% block css %}
    <style>
        .mes-input{
            margin-bottom: 10px;
            width: 23%;
        }
        .mes-select{
            width: 23.2%;
        }
        input{
            width: 90%;
        }
    </style>
{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}


{% block left_body_top %}
    {{ parent() }}
{% endblock %}


{% block left_body %}
    {{ parent() }}
{% endblock %}


    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">企业信息查询</span>
            </div>
        </div>
        <div class="main-content">
            <div class="main-top">
                <div class="index-list index-m1">
                    <div class="index-total">企业总数</div>
                    <div class="index-totalNum">
                        <span>{{ data.company_count }}</span>个
                    </div>
                </div>
                <div class="index-list qy-m2">
                    <div class="index-total" style="padding-top: 11px;">本月新增企业数</div>
                    <div class="index-totalNum">
                        <span>{{ data.month_company_count }}</span>个
                    </div>
                </div>
                <div class="index-list qy-m3">
                    <div class="index-total">今日新增企业数</div>
                    <div class="index-totalNum">
                        <span>{{ data.day_company_count }}</span>个
                    </div>
                </div>
            </div>

            <div class="mes-content">
                <div class="main-mes-top">

                    <div style="overflow: hidden;">
                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" name="select_credit_code" placeholder="请输入统一社会信用代码">
                        </div>

                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" name="select_name" placeholder="请输入企业名称">
                        </div>


                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" name="select_user_name" placeholder="请输入科技联络人姓名">
                        </div>

                    </div>
                    <div style="overflow: hidden;">
                        <select name="select_company_attribute_id" class="mes-select fl">
                            <option value="">请选择企业属性</option>
                            {% for item in data.attribute %}
                                <option value="{{ item.id }}">{{ item.company_attribute_name }}</option>
                            {% endfor %}
                        </select>

                        <select name="select_company_category_id" class="mes-select fl">
                            <option value="">请选择企业类别</option>
                            {% for item in data.category %}
                                <option value="{{ item.id }}">{{ item.company_category_name }}</option>
                            {% endfor %}
                        </select>

                        <select name="select_admin_id" class="mes-select fl">
                            <option value="">请选择科技载体</option>
                            {% for item in data.teac_admin %}
                                <option value="{{ item.id }}">{{ item.nickname }}</option>
                            {% endfor %}
                        </select>


                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released fl">企业列表</div>
                    <div class="acc-operation fr">
                        <a href="{{ path('admin_export',{'role_id':1}) }}" class="acc-opera-btn fl disable-btn">导出</a>
                    </div>

                    <table class="table company-table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th class="center-th">序号</th>
                            <th class="center-th">企业名称</th>
                            <th class="center-th">企业属性</th>
                            <th class="center-th">企业类别</th>
                            <th class="center-th">统一社会信用代码</th>
                            <th class="center-th">科技载体</th>
                            <th class="center-th">科技联络人</th>
                            <th class="center-th">详情</th>
                        </tr>
                        </thead>
                        <tbody>




                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">



                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% endblock %}



{% block body %}{% endblock %}

{% block box %}

    <div class="pop-status opacity"></div>

    <!--科技联络人-->
    <div class="pop-second pop-liaison" style="display: none;">
        <div class="pop-title">
            科技联络人
            <span class="close close-icon"></span>
        </div>
        <div style="padding: 20px 30px;">
            <table class="table technolog-table" style="table-layout:fixed;">
                <thead>
                <tr style="background-color: #f3f9fd;">
                    <th class="center-th" width="20%;">姓名</th>
                    <th width="30%;">手机号</th>
                    <th>邮箱</th>
                </tr>
                </thead>
                <tbody>


                </tbody>
            </table>
        </div>
    </div>

{% endblock %}

{% block javascript %}
    {{ parent() }}
<script type="text/javascript">


        SidebarHighlighting(4);

        // 点击查询
        var select_credit_code = "";
        var select_name = "";
//        var select_fr_name = "";
        var select_user_name = "";
        var select_company_attribute_id = "";
        var select_company_category_id = "";
        var select_admin_id = "";
        $('.mes-query-btn').on('click', function() {
            select_credit_code = $("input[name='select_credit_code']").val();
            select_name = $("input[name='select_name']").val();
//            select_fr_name = $("input[name='select_fr_name']").val();
            select_user_name = $("input[name='select_user_name']").val();
            select_company_attribute_id = $("select[name='select_company_attribute_id']").val();
            select_company_category_id = $("select[name='select_company_category_id']").val();
            select_admin_id = $("select[name='select_admin_id']").val();

            page_times = 0;
            addSearchAction(1);
        });

        //点击取消
        $('.mem-cancel, .close-icon').on('click', function() {
            ComMesClose();
        });

        function ComMesClose() {
            $('.pop-status').hide();
            $('.pop-eqit-mes').hide();
            $('.pop-liaison').hide();
            $('.pop-classify').hide();
        }

        function ComMesOpen() {
            $('.pop-status').show();
        }


        // 科技联络人  ->  查看详情
        $('body').on('click','.table-opera.lia-detail', function() {
            $(".technolog-table tbody").empty();
            ComMesOpen();
            var id = $(this).data("id");
            var he_lia = $('.pop-liaison');

            $.getJSON("{{ path('api_platform_get_company_technological') }}",{id:id},function(data){
                console.log(data);

                if(data.errorCode == 0){
                    var item = data.data;
                    for(var i in item){
                        var html = '';

                        if(item[i].name == null){
                            item[i].name = "";
                        }

                        html += '<tr>';
                        html += '<td class="center-th">'+ item[i].name +'</td>';
                        html += '<td>'+ item[i].phone +'</td>';
                        html += '<td>'+ item[i].email +'</td>';
                        html += '</tr>';

                        $(".technolog-table tbody").append(html);
                    }

                } else {
                    {#var load_url = "";#}
                    {#if(data.errorCode == -1){#}

                        {#load_url = "{{ path('plat_auth_login') }}";#}
                    {#}#}

                    popStatus(2, data.message,1,"",true);
                }


            })

            he_lia.show();
        });


        // 获取列表
        var page_times = 0;
        function getList(page,select_credit_code,select_name,select_user_name,select_company_attribute_id,select_company_category_id,select_admin_id){
            page_times++;
            var param = {page:page};

            param.credit_code = select_credit_code;
            param.name = select_name;
            param.user_name = select_user_name;
            param.company_attribute_id = select_company_attribute_id;
            param.company_category_id = select_company_category_id;
            param.admin_id = select_admin_id;

            $.getJSON("{{ path('api_platform_company_list') }}",param,function(data){

                $(".company-table tbody").empty(); //3
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                if(allpage == 0){
                    $(".pagination").empty();
                }


                var item = data.data.info;
                for(var i in item){
                    var html = '';
                    var key = parseInt(i)+1;

                    var list_order_num = parseInt((parseInt(page)-1)*10+key);

                    var info_url = "{{ path('plat_company_detail_message',{id:'784579325653'}) }}".replace("784579325653",item[i].id);

                    html += '<tr>';
                    html += '<td class="a-line center-th">'+ list_order_num +'</td>';
                    html += '<td class="center-th">'+ item[i].name +'</td>';
                    html += '<td class="center-th">'+ item[i].company_attribute +'</td>';
                    html += '<td class="center-th">'+ item[i].company_category +'</td>';
                    html += '<td class="center-th">'+ item[i].credit_code +'</td>';
                    html += '<td class="center-th">'+ item[i].admin +'</td>';
                    html += '<td class="center-th">';
                    html += '<span class="table-opera lia-detail" data-id="'+ item[i].id +'">查看详情</span>';
                    html += '</td>';
                    html += '<td class="center-th">';
                    html += '<a href="'+ info_url +'">查看详情</a>';
                    html += '</td>';
                    html += '</tr>';

                    $(".company-table tbody").append(html);
                }




            })
        }

        addSearchAction(1);  //4

        //5
        function addSearchAction(page){

            getList(page,select_credit_code,select_name,select_user_name,select_company_attribute_id,select_company_category_id,select_admin_id);
        }
</script>
{% endblock %}